package link.anyauto.web;

import java.io.Serializable;

import static spark.Spark.*;

/**
 * Created by Administrator on 2016/8/10.
 */
public class Hello {
    static JsonTransformer transformer = new JsonTransformer();
    public static void main(String[] args) throws Exception {

        System.out.println(Serializable.class.isAssignableFrom(User.class));
        System.out.println(Serializable.class.isAssignableFrom(UserBuilder.class));
        System.out.println(Serializable.class.getName());
        System.out.println(Serializable.class.getSimpleName());

        get("/hello", (req, res) -> "<h1>Hello world here we come!</h1>");

        get("/session", (req, res) -> {
            String name = req.queryMap().get("name").value();
            if(name != null) {
                req.session().attribute("name", name);
            }
            return "<h1>Hello " + req.session().attribute("name") + "</h1>";
        });

        get("/user", (req, res) -> {
            User user = new UserBuilder().createUser();
            user.name = "小明";
            user.age = 15;
            user.gender = "女";
            user.id = "1024";
            user.pwd = "pwd";
            return user;
        }, transformer);

        get("/user/:id", (req, res) -> {
            User user = new UserBuilder().createUser();
            user.name = "小明";
            user.age = 15;
            user.gender = "女";
            user.id = req.params(":id");
            user.pwd = "pwd";
            return user;
        }, transformer);
        post("/", (req, res) -> {
            System.out.println("Try to save something here");
            return "Information Saved";
        });
    }
}
